package com.bank.lenovoz5;

import android.graphics.Point;
import android.os.RemoteException;
import android.support.test.uiautomator.UiDevice;
import android.support.test.uiautomator.UiObject;
import android.support.test.uiautomator.UiObjectNotFoundException;
import android.support.test.uiautomator.UiSelector;
import android.text.TextUtils;
import android.util.Log;

import com.bank.Bank;
import com.entity.User;
import com.receive.SMSReceiverSend;
import com.show.api.util.StringUtils;
import com.utils.ChatClient;
import com.utils.CodeUtils;
import com.utils.Constants;
import com.utils.FileHelper;
import com.utils.ImageView;
import com.utils.LogToFile;
import com.utils.UIUtils;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static android.os.SystemClock.sleep;
import static com.bank.Bank.sumMoney;
import static com.utils.ChatClient.C_updateBalance_W;
import static com.utils.ChatClient.ConfirmOrder;
import static com.utils.ChatClient.PAUSE;
import static com.utils.ChatClient.RUNING;
import static com.utils.ChatClient.S_paused_C;
import static com.utils.ChatClient.addWorkTime;
import static com.utils.ChatClient.getSerialNumber;
import static com.utils.ChatClient.getmap;
import static com.utils.ChatClient.list;
import static com.utils.ChatClient.mapDelete;
import static com.utils.ChatClient.pressu;
import static com.utils.ChatClient.setDevicesLog;
import static com.utils.ChatClient.user;
import static com.utils.ChatClient.userInfo;
import static com.utils.Constants.orderBankName;

/**
 * 项目名称：app
 * 类描述：Z5工商银行脚本
 * 创建人：Administrator
 * 创建时间：2019/11/12 10:48
 * 修改人：Administrator
 * 修改时间：2019/11/12 10:48
 * 修改备注：
 */
public class Z5ICBCbank {
    private Bank bank;
    private final UiDevice mDevice;

    private String type = "abc";
    public boolean login = false;
    private boolean isGestureLogin = true;//手势登录
    private int[][] xy_num_sms = new int[][]{
            {360, 2015},
            {180, 1535}, {545, 1535}, {900, 1535},
            {180, 1700}, {545, 1700}, {900, 1700},
            {180, 1860}, {545, 1860}, {900, 1860}};
    private int[][] xy_abc = new int[][]{
            {60, 1800}, {160, 1800}, {275, 1800}, {374, 1800}, {485, 1800}, {592, 1800}, {700, 1800}, {805, 1800}, {915, 1800}, {1022, 1800},
            {55, 1920}, {165, 1920}, {275, 1920}, {374, 1920}, {485, 1920}, {592, 1920}, {700, 1920}, {805, 1920}, {915, 1920},
            {160, 2050}, {270, 2050}, {380, 2050}, {485, 2050}, {590, 2050}, {700, 2050}, {805, 2050}};
    private float ratio;

    public Z5ICBCbank(Bank bank) throws InterruptedException, UiObjectNotFoundException {
        this.bank = bank;
        this.mDevice = bank.mDevice;
        this.ratio = bank.ratio;
        info();
    }

    /**
     * @throws UiObjectNotFoundException
     */
    public void info() throws UiObjectNotFoundException, InterruptedException {
        sleep(ChatClient.overtime_5);
        //获取页面上转账汇款节点
        ChatClient.begintime = System.currentTimeMillis();
        while (true) {
            boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_40, ChatClient.errorStr, Constants.isReport);
            if (isOutTime) {
                return;
            }
            UiObject sj = mDevice.findObject(new UiSelector().text("暂不更新").resourceId("android:id/button2"));
            UiObject qx = mDevice.findObject(new UiSelector().text("取消").className("android.widget.Button"));
            UiObject zhuanzhang = mDevice.findObject(new UiSelector().text("转账汇款").resourceId("com.icbc:id/icon_txt"));
            UiObject login_ = mDevice.findObject(new UiSelector().text("已注册手机银行，直接登录").resourceId("com.icbc:id/mobilebank_btn"));
            UiObject mTV_msg = mDevice.findObject(new UiSelector().resourceId("com.icbc:id/adp_message").textContains("检测到您的系统存在hook风险"));
            UiObject mTV_msg1 = mDevice.findObject(new UiSelector().resourceId("com.icbc:id/adp_message").textContains("为了保护您的账户及资金安全"));

            if (sj.exists()) {
                showMsg("点掉更新");
                sj.click();
            } else if (qx.exists()) {
                showMsg("点掉广告");
                qx.click();
            } else if (login_.exists()) {
                login_.click();
            } else if (mTV_msg.exists()) {
                showMsg("点掉Root警告");
                UiObject mBT = mDevice.findObject(new UiSelector().text("确定").resourceId("com.icbc:id/adp_button1"));
                if (mBT.exists()) {
                    mBT.click();
                    sleep(ChatClient.overtime_2);
                }
            } else if (mTV_msg1.exists()) {
                showMsg("点掉环境警告");
                UiObject mBT = mDevice.findObject(new UiSelector().text("继续使用").resourceId("com.icbc:id/adp_button2"));
                if (mBT.exists()) {
                    mBT.click();
                    sleep(ChatClient.overtime_2);
                }
            } else if (zhuanzhang.exists()) {
                zhuanzhang.click();
                showMsg("点击《转账汇款》，开始检测错误弹窗");
                sleep(ChatClient.overtime_3);
                checkLoginErrorDialog();
                break;
            }
        }
        //连接服务端
        ChatClient.start();
        //获取账号信息
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_40, "获取登录信息超时...", Constants.isReport);
            if (isOutTime) {
                return;
            }
            if (userInfo.equals("")) {
                ChatClient.msg("<YZF>{'header':'" + ChatClient.M_GET_BANK_LOGIN_INFO_P + "'}</YZF>");
                sleep(ChatClient.overtime_5);
            } else {
                user = new User();
                String[] res = userInfo.split(" ");
                for (int i = 0; i < res.length; i++) {
                    switch (i) {
                        case 0:
                            user.setUserName(res[0].split("_")[0]);
                            break;
                        case 1:
                            user.setPwd(res[1]);
                            break;
                        case 2:
                            user.setBankpwd(res[2]);
                            break;
                        case 3:
                            user.setUsbPayPwd(res[3]);
                            break;
                        case 4:
                            user.setUseType(res[4]);
                            break;
                        case 5:
                            user.setBankId(res[5]);
                            break;
                        case 6:
                            user.setUsePayMode(res[0].split("_")[1]);
//                            user.setUsePayMode("0");
                            break;

                    }
                }
                break;
            }
        }
        sleep(ChatClient.overtime_5);
        Login();
    }

    private void checkLoginErrorDialog() throws UiObjectNotFoundException {
        showMsg("开始检测错误弹窗");
        long timeMillis = System.currentTimeMillis();
        while (true) {
            boolean isOutTime = CodeUtils.outTime(timeMillis, ChatClient.overtime_5, "点击了登陆，检测错误弹窗完成", Constants.notReport);
            if (isOutTime) {
                break;
            }
            UiObject btn = mDevice.findObject(new UiSelector().resourceId("android:id/button1"));
            if (btn.exists()) {
                showMsg("检测到错误弹窗，点击了关闭");
                btn.click();
            }
            UiObject btn1 = mDevice.findObject(new UiSelector().resourceId("ebdp-pop-add-img1"));
            if (btn1 != null && btn1.exists()) {
                showMsg("检测到安全升级弹窗，点击关闭");
                btn1.click();
            }
            sleep(ChatClient.overtime_1);
        }
    }

    //进入登录页面补充用户信息
    public void Login() throws InterruptedException, UiObjectNotFoundException {
        long startCheckErrorDialog = System.currentTimeMillis();
        while (true) {
            boolean outTime = CodeUtils.outTime(startCheckErrorDialog, ChatClient.overtime_5, "境内汇款超时", Constants.notReport);
            if (outTime) {
                break;
            }
            UiObject title1 = CodeUtils.getUiObject_textOrClass("汇款明细", "android.widget.Button");
            UiObject title2 = mDevice.findObject(new UiSelector().text("转账汇款").resourceId("nav_title"));
            if (title1.exists() || title2.exists()) {
                mDevice.click(545, 560);
                mDevice.click(545, 560);
                sleep(ChatClient.overtime_1);
                checkLoginErrorDialog();
                break;
            }
            showMsg("获取--转账汇款");
            sleep(ChatClient.overtime_1);
        }

        sleep(ChatClient.overtime_2);
        String pwd = user.getPwd();
        if (TextUtils.isEmpty(pwd)) {
            showMsg("user.getPwd()==null");
            return;
        }
        if (isGestureLogin) {
            gestureLogin(pwd);//手势登录
        } else {
            clickLandingPsw(pwd);//输入密码登录
        }
        sleep(3000);
        //进入转账页面
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_40, ChatClient.errorStr, Constants.isReport);
            if (isOutTime) {
                return;
            }
            UiObject title1 = mDevice.findObject(new UiSelector().text("汇款明细").className("android.widget.Button"));
            UiObject zhuanzhang = mDevice.findObject(new UiSelector().resourceId("accountname"));
            if (title1.exists()) {
                showMsg("===登陆点击完成，汇款明细页面，点击境内汇款页面==");
                mDevice.click(540, 420);
                mDevice.click(540, 420);
            } else if (zhuanzhang.exists()) {
                //登录成功
                ChatClient.loginS();
                showMsg("=====登录成功========");
                sleep(1000);
                break;
            }
        }
        //是否从在订单
        setRemittance();
    }

    private void gestureLogin(String password) {
        char[] pwd = password.toCharArray();//char数组
        showMsg("password======");
        Point[] pp = new Point[pwd.length];
        for (int i = 0; i < pwd.length; i++) {
            Point point = new Point();
            int p = Integer.valueOf(pwd[i] + "") - 1;
            point.set(xy_gesture_2016[p][0], xy_gesture_2016[p][1]);
            showMsg("pwd======" + i);
            pp[i] = point;
        }
        // 唤醒屏幕
        try {
            mDevice.wakeUp();
        } catch (RemoteException e) {
            e.printStackTrace();
        }
        mDevice.swipe(pp, 10);
    }

    // 2016分辨率 手势密码坐标顺序为：123456789
    private int[][] xy_gesture_2016 = new int[][]{
            {230, 935}, {540, 935}, {850, 935},
            {230, 1245}, {540, 1245}, {850, 1245},
            {230, 1560}, {540, 1560}, {850, 1560}
    };

    /**
     * 点击登录密码
     *
     * @param password
     * @throws RemoteException
     */
    private void clickLandingPsw(String password) throws UiObjectNotFoundException, InterruptedException {
        while (true) {
            UiObject pwd1 = mDevice.findObject(new UiSelector().resourceId("com.icbc:id/login_password"));
            if (pwd1.exists()) {
                pwd1.legacySetText("");
                break;
            }
        }
        sleep(1000);
        //模拟用户输入登录密码
        putPwd(password);
        //验证码
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            long nowtime = System.currentTimeMillis();
            if ((nowtime - ChatClient.begintime) > 3000) {
                break;
            }
            UiObject yzm = mDevice.findObject(new UiSelector().text("验证码，点击图片可刷新").resourceId("com.icbc:id/login_verifycode"));
            //判断是否进入转账页面
            if (yzm.exists()) {
                imageCode_f();
                sleep(1000);
                break;
            }
        }
        mDevice.click((int) (360 * ratio), (int) (220 * ratio));
        sleep(1000);
        UiObject loing = mDevice.findObject(new UiSelector().text("登录").resourceId("com.icbc:id/login_btn"));
        if (loing.exists()) {
            loing.click();
            showMsg("===点击了登录==");
        }
    }

    /**
     * 登录成功后进入转账
     *
     * @throws UiObjectNotFoundException
     */
    public void setRemittance() {
        try {
            while (true) {
                sleep(ChatClient.overtime_3);
                RUNING = list.size() > 0;
                if (RUNING) {
                    orderBankName = Constants.getBank(list.get(0).getBankName(), "ICBC");
                    if (ConfirmOrder) {
                        //查账
                        auditOrder();
                    } else {
                        //转账
                        remittanceLongin();
                    }
                } else {
                    if (PAUSE) {
                        remittance1();
                    } else {
                        S_paused_C();
                        sleep(1000);
                    }
                }
            }
        } catch (Exception e) {
            setDevicesLog(e.getMessage());
            e.printStackTrace();
        }
    }

    /**
     * 附加图形验证码
     *
     * @throws UiObjectNotFoundException
     */
    public void imageCode_f() {
        try {
            while (true) {
                String code = ImageView.getImage("com.icbc:id/verifycode_imageview", "");
                showMsg("===code==-----==:" + code);
                if (!code.equals("")) {
                    UiObject et_code2 = mDevice.findObject(new UiSelector().resourceId("com.icbc:id/login_verifycode"));
                    et_code2.legacySetText("");
                    et_code2.setText(code);
                    sleep(1000);
                    mDevice.click((int) (663 * ratio), (int) (816 * ratio));
                    sleep(1000);
                    showMsg("===code==+++==:" + code);
                    break;
                }
            }
        } catch (Exception e) {
            setDevicesLog(e.getMessage());
            e.printStackTrace();
        }
    }

    /**
     * 转账汇款
     */
    public void remittanceLongin() {
        try {
            ChatClient.begintime = System.currentTimeMillis();//开始时间
            while (true) {
                boolean outTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_30, "账户姓名超时...", Constants.isReport);
                if (outTime) {
                    return;
                }
                UiObject username_ = mDevice.findObject(new UiSelector().resourceId("accountname"));
                if (username_.exists()) {
                    username_.setText(list.get(0).getUserName());
                    showMsg("===输入账户姓名====");
                    break;
                }
            }
            UiObject moeny = mDevice.findObject(new UiSelector().resourceId("payCardNumtmp_selectpanel"));
            sumMoney = moeny.getChild(new UiSelector().className("android.view.View").index(2)).getContentDescription();
            if (!sumMoney.contains("元")) {
                sumMoney = moeny.getChild(new UiSelector().className("android.view.View").index(2)).getText();
            }
            sumMoney = sumMoney.replaceAll("元", "");
            sumMoney = sumMoney.replaceAll(",", "");

            if (sumMoney.equals("")) {
                sumMoney = "-1";
            }
            showMsg("=====获取当前金额=====" + sumMoney);
            //账户余额是否大于转账金额
            if (Double.parseDouble(sumMoney) < Double.parseDouble(list.get(0).getMoney())) {
                showMsg("=====账户余额不足=====");
                ChatClient.reportTransferOrder(bank.BANK_NAME, "账户余额不足", sumMoney, 1);
                sleep(ChatClient.overtime_1);
                mDevice.click((int) (90 * ratio), (int) (100 * ratio));
                sleep(ChatClient.overtime_1);
                mDevice.click((int) (90 * ratio), (int) (100 * ratio));
                ChatClient.begintime = System.currentTimeMillis();//开始时间
                while (true) {
                    boolean outTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_30, "《转账汇款》查询超时...", Constants.isReport);
                    if (outTime) {
                        return;
                    }
                    UiObject zhuanzhang = CodeUtils.getUiObject_textOrClass("转账汇款", "android.widget.TextView");
                    if (zhuanzhang.exists()) {
                        zhuanzhang.click();
                        break;
                    }
                }
                //进入转账页面
                ChatClient.begintime = System.currentTimeMillis();//开始时间
                while (true) {
                    boolean outTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_30, "《转账汇款》超时...", Constants.isReport);
                    if (outTime) {
                        mDevice.click((int) (360 * ratio), (int) (290 * ratio));
                        break;
                    }
                    UiObject zhuanzhang = CodeUtils.getUiObject_textOrClass("转账汇款", "android.view.View");
                    //判断是否进入转账页面
                    if (zhuanzhang.exists()) {
                        mDevice.click((int) (360 * ratio), (int) (290 * ratio));
                        break;
                    }
                }
                return;
            }
            if (!sumMoney.equals("-1")) {
                // 保存余额后面错误查账比对使用
                showMsg("本地保存余额");
                C_updateBalance_W(Double.parseDouble(sumMoney));
                String sumMoneyFile = user.getUserName() + bank.BANK_FLAG + "_sumMoney.txt";
                FileHelper.saveMoneySDFile(false, sumMoney, sumMoneyFile);
                sleep(ChatClient.overtime_1);
            }
            mDevice.click((int) (360 * ratio), (int) (1220 * ratio));
            sleep(ChatClient.overtime_2);
            UiObject bankNo = mDevice.findObject(new UiSelector().resourceId("callInfo"));//输入新收款卡号-点击输入姓名会看到
            if (bankNo.exists()) {
                bankNo.click();
            }
            UiObject bankNo_ = mDevice.findObject(new UiSelector().resourceId("cardnum"));
            if (bankNo_.exists()) {
                bankNo_.setText(list.get(0).getBankNo());
                showMsg("===输入卡号====");
            }
            sleep(ChatClient.overtime_1);
            ChatClient.begintime = System.currentTimeMillis();//开始时间
            while (true) {
                boolean outTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_30, "输入金额超时...", Constants.isReport);
                if (outTime) {
                    return;
                }
                UiObject moeny_0 = mDevice.findObject(new UiSelector().resourceId("inPriceTmp"));
                //判断是否进入转账页面
                if (moeny_0.exists()) {
                    moeny_0.setText(list.get(0).getMoney());
                    showMsg("=====输入金额====");
                    break;
                }
            }
            sleep(ChatClient.overtime_1);
            showMsg("判定银行识别");
            mDevice.click(120, 666);
            sleep(ChatClient.overtime_2);
            if (!selsctBankName()) {
                return;
            }
            sleep(ChatClient.overtime_2);
            ChatClient.begintime = System.currentTimeMillis();//开始时间
            while (true) {
                boolean outTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_30, "转账金额超时...", Constants.isReport);
                if (outTime) {
                    return;
                }
                UiObject moeny_00 = mDevice.findObject(new UiSelector().resourceId("inPriceTmp"));
                //判断是否进入转账页面
                if (moeny_00.exists()) {
                    if (CodeUtils.getUiObject_content(moeny_00).equals("免手续费")) {
                        moeny_00.setText(list.get(0).getMoney());
                        showMsg("=====输入金额======");
                    } else {
                        break;
                    }
                    sleep(500);
                }
            }
            //下一步
            showMsg("=====点击下一步=====");
            setNext();
        } catch (Exception e) {
            setDevicesLog(e.getMessage());
            e.printStackTrace();
        }
    }

    private boolean selsctBankName() throws UiObjectNotFoundException {
        //进入收款银行选择
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            boolean outTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_30, "点击选择银行...", Constants.notReport);
            if (outTime) {
                mDevice.click((int) (626 * ratio), (int) (370 * ratio));
                break;
            }
            UiObject zhuanzhang = mDevice.findObject(new UiSelector().resourceId("accountbank"));
            UiObject zhuanzhang1 = mDevice.findObject(new UiSelector().resourceId("com.icbc:id/search_text"));
            //判断是否进入转账页面
            if (zhuanzhang.exists()) {
                String bnakName = zhuanzhang.getText();
                if (bnakName.contains("请选择银行")) {
                    zhuanzhang.click();
                    showMsg("=====进入选择银行加载中====");
                } else {
                    showMsg("银行名为：" + bank.BANK_NAME);
                    return true;
                }
            }
            //判断是否进入转账页面
            if (zhuanzhang1.exists()) {
                break;
            }
        }
        //进入收款银行选择
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            long nowtime = System.currentTimeMillis();
            if ((nowtime - ChatClient.begintime) > ChatClient.overtime) {
                ChatClient.timer(LogToFile.getMethodName(), ChatClient.errorStr);
                return false;
            }
            UiObject zhuanzhang = mDevice.findObject(new UiSelector().text("请选择收款银行").resourceId("com.icbc:id/navbar_title"));
            //判断是否进入转账页面
            if (zhuanzhang.exists()) {
                showMsg("=====进入选择银行页面====");
                break;
            }
        }
        sleep(ChatClient.overtime_2);
        showMsg("=====收款银行====" + orderBankName);
        if (orderBankName.indexOf("工商") != -1) {
            showMsg("=====收款银行是行内转账====" + orderBankName);
            mDevice.click(120, 660);
        } else {
            long startSearchTime = System.currentTimeMillis();
            while (true) {
                boolean outTime = CodeUtils.outTime(startSearchTime, ChatClient.overtime_30, "转账超时1...", Constants.isReport);
                if (outTime) {
                    return false;
                }
                //获取收款银行控件
                UiObject bankName_search = mDevice.findObject(new UiSelector().resourceId("com.icbc:id/search_text"));
                showMsg("=====检索收款银行====");
                //sleep(2000);
                if (bankName_search.exists()) {
                    showMsg("=====检索搜索银行====");
                    bankName_search.click();
                    bankName_search.setText(orderBankName);
                    break;
                }
                sleep(ChatClient.overtime_1);
            }
            sleep(ChatClient.overtime_2);
            //检查是否检索到银行
            ChatClient.begintime = System.currentTimeMillis();//开始时间
            while (true) {
                boolean outTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_10, "收款银行超时...", Constants.notReport);
                UiObject bankname = mDevice.findObject(new UiSelector().resourceId("com.icbc:id/iv_xiaozhi"));
                if (bankname.exists() || outTime) {
                    showMsg("=====收款银行异常====");
                    ChatClient.reportTransferOrder(bank.BANK_NAME, "收款银行名异常", sumMoney, 1);
                    sleep(ChatClient.overtime_1);
                    //返回
                    showMsg("返回列表");
                    mDevice.click(50, 160);
                    sleep(1000);
                    showMsg("返回上页");
                    mDevice.click(50, 160);
                    //进入转账页面
                    while (true) {
                        UiObject mTV = mDevice.findObject(new UiSelector().className("android.view.View").text("境内汇款"));
                        //判断是否进入转账页面
                        if (mTV.exists()) {
                            showMsg("进入转账页面");
                            mTV.click();
                            break;
                        }
                    }
                    return false;
                }
                UiObject zhuanzhang = mDevice.findObject(new UiSelector().text(orderBankName).resourceId("com.icbc:id/receipt_bank_name"));
                //判断是否进入转账页面
                if (zhuanzhang.exists()) {
                    zhuanzhang.click();
                    showMsg("=====确定收款银行====");
                }
                UiObject mBT_next = mDevice.findObject(new UiSelector().className("android.widget.Button").text("下一步"));
                if (mBT_next.exists()) {
                    showMsg("银行名选择成功");
                    break;
                }
            }
        }

        sleep(2000);
        while (true) {
            UiObject Progressbar = mDevice.findObject(new UiSelector().resourceId("com.icbc:id/progress_wheel"));
            //判断是否进入转账页面
            if (Progressbar.exists()) {
                showMsg("=====选择银行后返回加载中====");
                sleep(ChatClient.overtime_2);
            } else {
                break;
            }
        }
        return true;
    }

    /**
     * 获取余额
     */
    private void getBalance() throws UiObjectNotFoundException {
        Exception exception = new Exception();
        StackTraceElement[] trace = exception.getStackTrace();
        String method = trace[0].getMethodName();
        sleep(2000);
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            long nowtime = System.currentTimeMillis();
            if ((nowtime - ChatClient.begintime) > 40 * 1000) {
                showMsg("----进入转账页面超时-----");
                ChatClient.timer(method, ChatClient.errorStr);
                break;
            }
            UiObject zhuanzhangB = mDevice.findObject(new UiSelector().resourceId("payCardNumtmp_selectpanel"));
            //判断是否进入转账页面
            if (zhuanzhangB.exists()) {
                sleep(3000);
                UiObject moeny = mDevice.findObject(new UiSelector().resourceId("payCardNumtmp_selectpanel"));
                sumMoney = moeny.getChild(new UiSelector().className("android.view.View").index(2)).getContentDescription();
                if (!sumMoney.contains("元")) {
                    sumMoney = moeny.getChild(new UiSelector().className("android.view.View").index(2)).getText();
                }
                sumMoney = sumMoney.replaceAll("元", "");
                sumMoney = sumMoney.replaceAll(",", "");
                showMsg("===moeny====" + sumMoney + "===");
                if (!sumMoney.equals("-1")) {
                    C_updateBalance_W(Double.parseDouble(sumMoney));
                    sleep(1000);
                }
                break;
            }
        }
    }

    /**
     * 查账
     *
     * @throws UiObjectNotFoundException
     */
    public void auditOrder() throws UiObjectNotFoundException, InterruptedException {
        showMsg("===获取余额=====");
        getBalance();
        //返回
        //进入汇款明细
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_30, "返回上页超时...", Constants.isReport);
            if (isOutTime) {
                return;
            }
            UiObject back = CodeUtils.getUiObject_textOrClass("返回", "android.widget.Button");
            if (back.exists()) {
                back.click();
                break;
            }
        }
        //进入汇款明细
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_30, "回款明细查找超时...", Constants.isReport);
            if (isOutTime) {
                return;
            }
            UiObject next = CodeUtils.getUiObject_textOrClass("汇款明细", "android.widget.Button");
            if (next.exists()) {
                showMsg("点击汇款明细");
                next.click();
                mDevice.click(950, 160);
                break;
            }
        }
        //判断是否进入交易明细
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_30, "交易明细超时...", Constants.isReport);
            if (isOutTime) {
                return;
            }
            UiObject next = CodeUtils.getUiObject_textOrId("交易明细", "com.icbc:id/navbar_title");
            if (next.exists()) {
                showMsg("进入交易明细");
                break;
            }
        }

        //获取交易记录
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            UiObject mTV_text = CodeUtils.getUiObject_containTextOrClass("最近一个月没有境内汇款交易明细", "android.widget.TextView");
            boolean outTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_30, "查询超时...", Constants.notReport);
            if (outTime || mTV_text.exists()) {
                ChatClient.reportAuditOrder("6", bank);
                break;
            }
            String username = CodeUtils.getUiObject_id_text("com.icbc:id/tv_titleLabel");
            String money = CodeUtils.getUiObject_id_text("com.icbc:id/tv_titleValue");
            String bankNo = CodeUtils.getUiObject_id_text("com.icbc:id/tv_subtitleLabel");
            String bankNo0 = "尾号" + list.get(0).getBankNo().substring(list.get(0).getBankNo().length() - 4, list.get(0)
                    .getBankNo().length());
            String moery1 = money.replace("-", "");
            moery1 = moery1.replaceAll(",", "");
            showMsg("金额是否相同：" + (Double.parseDouble(list.get(0).getMoney()) == Double.parseDouble(moery1)));
            showMsg("username===" + list.get(0).getUserName().equals(username));
            showMsg("bankNo=====" + bankNo0.equals(bankNo));
            String state = "1";
            if (Double.parseDouble(list.get(0).getMoney()) == Double.parseDouble(moery1) && list.get(0).getUserName().equals(username) &&
                    bankNo0.equals(bankNo)) {
                state = "0";
            } else {
                String sumMoneyFile = user.getUserName() + bank.BANK_FLAG + "_sumMoney.txt";
                String oldMoney = FileHelper.readSDFile(sumMoneyFile);
                state = Constants.changeInAmount(bank.BANK_FLAG, oldMoney, sumMoney, list.get(0).getMoney());
            }
            ChatClient.reportAuditOrder(state, bank);
            break;
        }
        //返回
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            boolean outTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_30, "返回超时...", Constants.isReport);
            if (outTime) {
                return;
            }
            Thread.sleep(ChatClient.overtime_1);
            UiObject back_0 = mDevice.findObject(new UiSelector().resourceId("com.icbc:id/navbar_left_btn"));
            if (back_0.exists()) {
                back_0.click();
                break;
            }
        }
        sleep(ChatClient.overtime_8);
        //进入转账
        mDevice.click((int) (360 * ratio), (int) (290 * ratio));
        sleep(ChatClient.overtime_1);
    }

    /**
     * 境内汇款页面
     */
    public void remittance1() {
        try {
            ChatClient.begintime = System.currentTimeMillis();//开始时间
            while (true) {
                boolean outTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_30, "银行卡号超时...", Constants.notReport);
                if (outTime) {
                    showMsg("=====超时点击===" + 380 * ratio + "," + 1000 + "坐标");
                    mDevice.click((int) (380 * ratio), 1000);
                    break;
                }
                UiObject back = mDevice.findObject(new UiSelector().resourceId("payCardNumtmp_selectpanel"));
                if (back.exists()) {
                    showMsg("=========点击银行卡号========");
                    back.click();
                    break;
                }
            }
            sleep(ChatClient.overtime_1);
            ChatClient.begintime = System.currentTimeMillis();//开始时间
            while (true) {
                boolean outTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_15, "超时点击返回转账页面...", Constants.notReport);
                if (outTime) {
                    mDevice.click((int) (380 * ratio), 300);
                    break;
                }
                UiObject view = mDevice.findObject(new UiSelector().resourceId("popselectpanel_container"));
                if (view.exists()) {
                    UiObject title = mDevice.findObject(new UiSelector().className("android.widget.ListView"));
                    if (title.exists()) {
                        showMsg("============点击返回转账页面========");
                        title.click();
                        break;
                    }
                }
            }
            sleep(ChatClient.overtime_3);
            showMsg("=========请求订单========");
            ChatClient.request();
            //进入转账页面
            ChatClient.begintime = System.currentTimeMillis();//开始时间
            while (true) {
                boolean outTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_40, "进入转账页面超时...", Constants.isReport);
                if (outTime) {
                    return;
                }
                UiObject zhuanzhangB = mDevice.findObject(new UiSelector().resourceId("payCardNumtmp_selectpanel"));
                //判断是否进入转账页面
                if (zhuanzhangB.exists()) {
                    sleep(3000);
                    UiObject moeny = mDevice.findObject(new UiSelector().resourceId("payCardNumtmp_selectpanel"));
                    sumMoney = moeny.getChild(new UiSelector().className("android.view.View").index(2)).getContentDescription();
                    if (!sumMoney.contains("元")) {
                        sumMoney = moeny.getChild(new UiSelector().className("android.view.View").index(2)).getText();
                    }
                    sumMoney = sumMoney.replaceAll("元", "");
                    sumMoney = sumMoney.replaceAll(",", "");
                    showMsg("===moeny====" + sumMoney + "===");
                    if (!sumMoney.equals("-1") && !sumMoney.contains("查询中")) {
                        C_updateBalance_W(Double.parseDouble(sumMoney));
                        showMsg("本地保存余额");
                        String sumMoneyFile = user.getUserName() + bank.BANK_FLAG + "_sumMoney.txt";
                        FileHelper.saveMoneySDFile(false, sumMoney, sumMoneyFile);
                        sleep(ChatClient.overtime_1);
                        break;
                    } else {
                        showMsg("网络错误...");
                        ChatClient.timer(LogToFile.getMethodName(), "获取余额失败...");
                    }
                }
            }
            ChatClient.waitExistOrder(ChatClient.overtime_60);
        } catch (Exception e) {
            setDevicesLog(e.getCause().getMessage());
            ChatClient.timer("remittance1", ChatClient.error);
            e.printStackTrace();
        }
    }

    //    public void setSMSClick(String code) {
    //        char[] num = "1234567890".toCharArray();//char数组
    //        char[] pwd = code.toCharArray();//char数组
    //        for (int j = 0; j < pwd.length; j++) {
    //            for (int i = 0; i < num.length; i++) {
    //                if (num[i] == pwd[j]) {
    //                    mDevice.click((int) (xy_num_sms[i][0]), (int) (xy_num_sms[i][1]));
    //                    sleep(ChatClient.overtime_1);
    //                    break;
    //                }
    //            }
    //        }
    //    }

    /**
     * 字母和数字键盘的切换
     *
     * @param checkStr
     * @return
     */
    public boolean isNumeric(String checkStr) {
        try {
            Integer.parseInt(checkStr);
            //切换数字键盘
            if (type.equals("abc")) {
                type = "123";
                mDevice.click((int) (385 * ratio), (int) (762 * ratio));
                sleep(1000);
            }
            return true;
        } catch (NumberFormatException err) {
            //切换字母键盘
            if (!type.equals("abc")) {
                type = "abc";
                mDevice.click((int) (500 * ratio), (int) (762 * ratio));
                sleep(1000);
            }
            return false;
        }
    }

    // 判断一个字符串是否含有数字
    public boolean HasDigit(String content) {
        boolean flag = false;
        Pattern p = Pattern.compile(".*\\d+.*");
        Matcher m = p.matcher(content);
        if (m.matches()) {
            flag = true;
        }
        return flag;
    }

    /**
     * 下一步
     *
     * @throws UiObjectNotFoundException
     */
    public void setNext() throws UiObjectNotFoundException, InterruptedException {
        //下一步
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_8, "下一步", Constants.notReport);
            if (isOutTime) {
                mDevice.click((int) (360 * ratio), (int) (762 * ratio));
                break;
            }
            UiObject btn_left = CodeUtils.getUiObject_contentText("暂不保存");
            if (btn_left.exists()) {
                btn_left.click();
                showMsg("=====关闭--暂不保存=====");
            }
            UiObject btn_left1 = CodeUtils.getUiObject_contentText("取消");
            if (btn_left1.exists()) {
                btn_left1.click();
                showMsg("=====关闭--额度提醒=====");
            }
            UiObject mBT_next = CodeUtils.getUiObject_textOrClass("下一步", "android.widget.Button");
            if (mBT_next.exists()) {
                mBT_next.click();
                showMsg("=====点击下一步=====");
                break;
            }
        }
        if (isOverMax(list.get(0).getMoney())) {
            showMsg("----开户行信息---" + list.get(0).getBankAdr());
            String[] array = list.get(0).getBankAdr().split("-");
            List<String> bankInfo = new ArrayList<>();
            String s = "";
            for (int i = 0; i < array.length; i++) {
                if (i < 2) {
                    bankInfo.add(array[i]);
                } else {
                    if (array.length == 3) {
                        bankInfo.add(array[i]);
                    } else {
                        showMsg("----开户行截取超过3---");
                        if (i == 2) {
                            s += array[i];
                        } else {
                            s += "-" + array[i];
                        }
                        showMsg("----拼接开户行后面的字段---");
                        if (i == array.length - 1) {
                            showMsg("----拼接完成---");
                            bankInfo.add(s);
                        }
                    }
                }
            }
            sleep(2000);
            showMsg("===准备进入选择省份====");
            setBankInfo(bankInfo);
        } else {
            if (errDialog()) {
                nextStep();
            }
        }
    }

    private boolean errDialog() throws UiObjectNotFoundException {
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            boolean outTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_5, "错误弹窗超时...", Constants.notReport);
            if (outTime) {
                break;
            }
            long nowtime = System.currentTimeMillis();
            if ((nowtime - ChatClient.begintime) > ChatClient.overtime_5) {
                showMsg("错误弹窗超时...");
                break;
            }
            UiObject mV = mDevice.findObject(new UiSelector().resourceId("myModalMsg"));
            if (mV.exists()) {
                UiObject mV_message = mV.getChild(new UiSelector().index(5).className("android.view.View"));
                if (mV_message.exists()) {
                    String text = mV_message.getText();
                    showMsg("订单信息错误--" + text);
                    reportOrder(text);
                    return false;
                }
            }
        }
        return true;
    }

    private void reportOrder(String msg) throws UiObjectNotFoundException {
        while (true) {
            UiObject mBT = mDevice.findObject(new UiSelector().resourceId("myModalBtn"));
            if (mBT.exists()) {
                mBT.click();
                String mobileD = "'devices':'" + getSerialNumber() + "','prot':'" + Constants.PROT + "','phoneModel':'工商银行'," +
                        "'info':'" + msg + "'";
                String json = "'order':'" + list.get(0).getOrder() + "','balance':'" + sumMoney + "','state':1,'type':1";
                ChatClient.msg("<YZF>{'header':'" + ChatClient.M_SEND_TRADE_RESULT_P + "'," + json + "," + mobileD + "}</YZF>");
                //删除处理过的订单
                mapDelete(list.get(0).getOrder());
                getmap();
                sleep(1000);
                mDevice.click((int) (90 * ratio), (int) (100 * ratio));
                //进入转账页面
                ChatClient.begintime = System.currentTimeMillis();//开始时间
                while (true) {
                    long nowtime = System.currentTimeMillis();
                    if ((nowtime - ChatClient.begintime) > ChatClient.overtime_30) {
                        mDevice.click((int) (360 * ratio), (int) (290 * ratio));
                        break;
                    }
                    UiObject zhuanzhang0 = mDevice.findObject(new UiSelector().text("转账汇款").className("android.widget.TextView"));
                    UiObject zhuanzhang1 = mDevice.findObject(new UiSelector().text("转账汇款").className("android.view.View"));
                    //判断是否进入转账页面
                    if (zhuanzhang0.exists()) {
                        showMsg("进入转账...");
                        zhuanzhang0.click();
                        sleep(ChatClient.overtime_2);
                    } else if (zhuanzhang1.exists()) {
                        mDevice.click((int) (360 * ratio), (int) (290 * ratio));
                        return;
                    }
                }
            }
        }
    }

    /**
     * U盾下一步
     */
    private void nextStep() throws UiObjectNotFoundException, InterruptedException {
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_5, "继续办理控件超时", Constants.notReport);
            if (isOutTime) {
                break;
            }
            UiObject mBT_cancel = CodeUtils.getUiObject_contentText("取消");
            if (mBT_cancel.exists()) {
                showMsg("=====关闭提示弹窗=====");
                mBT_cancel.click();
                sleep(ChatClient.overtime_1);
            }

            UiObject btn_left = CodeUtils.getUiObject_contentText("暂不保存");
            if (btn_left.exists()) {
                btn_left.click();
                showMsg("=====关闭--暂不保存=====");
            }
            UiObject mBT_next1 = CodeUtils.getUiObject_textOrId("继续办理", "bigAmt_remit_modal_confirm_okButton");
            if (mBT_next1.exists()) {
                mBT_next1.click();
                showMsg("=====继续办理=====");
                break;
            }
        }

        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            boolean outTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_8, "切换认证超时...", Constants.notReport);
            if (outTime) {
                break;
            }
            UiObject mTV_seitchPay = mDevice.findObject(new UiSelector().resourceId("choosemedium").text("切换认证方式"));
            if (mTV_seitchPay.exists()) {
                showMsg("点击切换认证方式");
                mTV_seitchPay.click();
                break;
            }
        }

        while (true) {
            UiObject mV_UDun = CodeUtils.getUiObject_textOrId("U盾认证", "myModalLabel");
            if (mV_UDun.exists()) {
                if (user.getUsePayMode().equals("0")) {
                    showMsg("U盾认证");
                    UKeyAttest();
                    break;
                } else {
                    showMsg("切换认证方式1...");
                    selertPayMode();
                    userPawAttest(user.getBankpwd());
                    smsAttest();
                    break;
                }
            }
            UiObject mV_sms = CodeUtils.getUiObject_textOrId("支付密码认证", "com.icbc:id/verifyControlDialogTitle2");
            if (mV_sms.exists()) {
                if (user.getUsePayMode().equals("1")) {//
                    showMsg("支付密码认证1");
                    userPawAttest(user.getBankpwd());
                    smsAttest();
                    break;
                } else {
                    showMsg("切换认证方式2...");
                    selertPayMode();
                    UKeyAttest();
                    break;
                }
            }
        }


        if (isOverMax(list.get(0).getMoney())) {
            //这里准备抓取非工作日
            showMsg("=====准备抓取非工作日===");
            ifStopDeal();
        }
        orderResult();
    }

    /**
     * 短信验证
     */
    private void smsAttest() throws UiObjectNotFoundException {
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_5, "无短信认证...", Constants.notReport);
            if (isOutTime) {
                return;
            }
            UiObject smsTitle = CodeUtils.getUiObject_textOrId("短信认证", "myModalLabel");
            if (smsTitle.exists()) {
                showMsg("需要短信认证");
                break;
            }
        }

        while (true) {
            UiObject mV = CodeUtils.getUiObject_textOrId("重新获取", "resendButton");
            if (mV.exists()) {
                showMsg("点击---重新获取");
                mV.click();
            }
            sleep(ChatClient.overtime_20);
            getSmsCodeType();
            if (getState()) {
                while (true) {
                    UiObject mV_fix = CodeUtils.getUiObject_textOrId("确定", "myModalOkBtn");
                    if (mV_fix.exists()) {
                        showMsg("点击短信验证确定...");
                        mV_fix.click();
                        break;
                    }
                }
                Constants.CODE = "";
                Constants.SMSMESSAGE = "";
                Constants.TV_TIPS = "";
                break;
            }
        }
    }

    /**
     * 获取短信序列号
     */
    public String getSmsCodeType() throws UiObjectNotFoundException {
        while (true) {
            String epayNo = CodeUtils.getUiObject_id_text("epayNo");
            if (!StringUtils.isEmpty(epayNo)) {
                Constants.TV_TIPS = epayNo;
                showMsg("===验证码序列号====" + Constants.TV_TIPS);
                return Constants.TV_TIPS;
            }
        }
    }

    /**
     * 请求短信
     *
     * @return
     */
    public boolean getState() throws UiObjectNotFoundException {
        showMsg("=====短信内容====" + Constants.SMSMESSAGE + "-----" + Constants.TV_TIPS + "+++++" + user.getUseType());
        while (true) {
            UiObject mET_sms = CodeUtils.getUiObject_textOrClass("请输入验证码", "android.widget.EditText");
            if (mET_sms.exists()) {
                showMsg("点击输入弹窗");
                mET_sms.click();
                sleep(ChatClient.overtime_2);
                mDevice.click(85,1920);
                sleep(ChatClient.overtime_1);
                break;
            }
        }
        if (user.getUseType().equals("1")) {//真机
            showMsg("有卡设备");
            if (!StringUtils.isEmpty(Constants.SMSMESSAGE)) {
                if (Constants.SMSMESSAGE.contains(Constants.TV_TIPS)) {
                    userPawAttest(Constants.CODE);
                    return true;
                }
            }
        } else {//无卡
            showMsg("无卡设备");
            ChatClient.requestSMSCode(user.getUserName(), user.getBankId());
            if (ChatClient.smsCode == null || TextUtils.isEmpty(ChatClient.smsCode.getSmscode())) {
                return false;
            } else {
                if (ChatClient.smsCode.getTelephone().equals(user.getUserName())) {
                    showMsg("收到短信验证码：" + ChatClient.smsCode.getSmscode());
                    userPawAttest(ChatClient.smsCode.getSmscode());
                    ChatClient.smsCode = null;
                    return true;
                } else {
                    String str = "收到短信验证码手机号不匹配";
                    showMsg(str + ChatClient.smsCode.getTelephone());
                    return false;
                }
            }
        }
        return false;
    }

    /**
     * U盾验证流程
     */
    private void UKeyAttest() throws UiObjectNotFoundException, InterruptedException {
        //选择U盾下一步
        mDevice.click(550, 2000);
        showMsg("=====点击U盾确认下一步=====");
        sleep(ChatClient.overtime_3);
        while (true) {
            UiObject ProgressBar = mDevice.findObject(new UiSelector().className("android.widget.ProgressBar"));
            if (ProgressBar.exists()) {
            } else {
                break;
            }
            sleep(ChatClient.overtime_1);
        }
        sleep(ChatClient.overtime_2);
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            boolean outTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_3, "链接断开超时...", Constants.notReport);
            if (outTime) {
                break;
            }
            UiObject pop = mDevice.findObject(new UiSelector().resourceId("com.icbc:id/adp_button1"));
            UiObject next_err = mDevice.findObject(new UiSelector().resourceId("com.icbc:id/adp_button2"));
            if (pop.exists()) {
                showMsg("=====再次点击下一步=====");
                pop.click();
                addWorkTime(ChatClient.overtime_20);
                setNext();
            }
            if (next_err.exists()) {
                showMsg("U盾链接错误，关闭弹窗");
                addWorkTime(ChatClient.overtime_20);
                next_err.click();
                showMsg("重新链接U盾");
                sleep(ChatClient.overtime_2);
                setNext();
                return;
            }
        }
        sleep(ChatClient.overtime_4);
        isABC = true;
        //截取键盘模拟用户输入登录密码
        if (user.getUsbPayPwd() != null && !(user.getUsbPayPwd().isEmpty())) {
            showMsg("=====当前为U盾模式==当前为U盾模式===");
            if (HasDigit(user.getUsbPayPwd())) {
                showMsg("切换数字键盘");
                //数字键盘切换
                mDevice.click(825, 1555);
                type = "123";
                //                getNum(user.getUsbPayPwd());
            } else {
                showMsg("=====输入U盾密码=====");
                putPwd(user.getUsbPayPwd());
            }
            sleep(ChatClient.overtime_3);
            //U盾确定
            mDevice.click(550, 1180);
            showMsg("=====盾密码输入完成==点击确定===");
            while (true) {
                UiObject Ud = mDevice.findObject(new UiSelector().text("确认信息").className("android.widget.TextView"));
                if (Ud.exists()) {
                    showMsg("=====请求点击U盾===");
                    //请求点击U盾
                    ChatClient.msg("<YZF>{'header':'" + ChatClient.M_TRANSFERFINISH_P + "'}</YZF>");
                    sleep(ChatClient.overtime_2);
                    pressu("3");
                    break;
                }
            }
        } else {
            while (true) {
                //如果U盾密码为空,就是短信
                showMsg("=====当前为短信模式==当前为短信模式===");
                String msmContent = SMSReceiverSend.MsmContent;
                sleep(2000);
                if (msmContent != null) {
                    String code = getCode(msmContent);
                    //点倒退键
                    for (int i = 0; i < 3; i++) {
                        mDevice.click(1020, 1920);
                        Thread.sleep(ChatClient.overtime_1);
                    }
                    showMsg("=====" + code + "===");
                    userPawAttest(code);
                    showMsg("=====点击下一步===");
                    UiObject uiObject = mDevice.findObject(new UiSelector().resourceId("myModalOkBtn").className("android.widget" +
                            ".Button"));
                    if (uiObject.exists()) {
                        uiObject.click();
                    }
                    break;
                }
            }
        }
    }

    /**
     * 支付密码验证
     */
    private void userPawAttest(String code) {
        char[] numChars = "0123456789".toCharArray();
        char[] pawChars = code.toCharArray();
        for (int j = 0; j < pawChars.length; j++) {
            for (int i = 0; i < numChars.length; i++) {
                if (numChars[i] == pawChars[j]) {
                    mDevice.click((xy_num_sms[i][0]), (xy_num_sms[i][1]));
                    showMsg("点击---+1");
                    sleep(ChatClient.overtime_1);
                    break;
                }
            }
        }
    }

    /**
     * 切换认证方式
     */
    private void selertPayMode() throws UiObjectNotFoundException {
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_8, "《切换认证方式》控件超时", Constants.notReport);
            if (isOutTime) {
                mDevice.click(920, 780);
                break;
            }
            UiObject mTV_seitchPay = CodeUtils.getUiObject_textOrId("切换认证方式", "com.icbc:id/rightUplink");
            if (mTV_seitchPay.exists()) {
                showMsg("点击切换认证方式");
                mTV_seitchPay.click();
                sleep(ChatClient.overtime_1);
                break;
            }
        }

        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_5, "认证方式超时", Constants.notReport);
            if (isOutTime) {
                break;
            }
            showMsg("user.getUsePayMode()======" + user.getUsePayMode() + "--------" + user.getUsePayMode().equals("0"));
            if (user.getUsePayMode().equals("0")) {
                UiObject mTV_seitchPay = CodeUtils.getUiObject_textOrClass("U盾", "android.view.View");
                if (mTV_seitchPay.exists()) {
                    showMsg("点击切换U盾");
                    mTV_seitchPay.click();
                    sleep(ChatClient.overtime_5);
                    break;
                }
            }
            if (user.getUsePayMode().equals("1")) {
                UiObject mTV_seitchPay = CodeUtils.getUiObject_textOrClass("支付密码", "android.view.View");
                if (mTV_seitchPay.exists()) {
                    showMsg("点击切换支付密码");
                    mTV_seitchPay.click();
                    sleep(ChatClient.overtime_5);
                    break;
                }
            }
        }
    }


    /**
     * U盾输入完成，后续步骤
     */
    private void orderResult() throws UiObjectNotFoundException {
        while (true) {
            UiObject info0 = CodeUtils.getUiObject_textOrClass("交易成功", "android.view.View");
            UiObject info2 = CodeUtils.getUiObject_textOrClass("交易失败", "android.view.View");
            UiObject info4 = CodeUtils.getUiObject_textOrClass("交易处理中", "android.view.View");
            UiObject info6 = CodeUtils.getUiObject_textOrClass("已实时到账", "android.view.View");
            UiObject info8 = CodeUtils.getUiObject_textOrClass("户名错误", "android.view.View");
            UiObject info10 = CodeUtils.getUiObject_textOrClass("交易已受理", "android.view.View");
            showMsg("---------检测交易结果----------");
            sleep(ChatClient.overtime_2);
            UiObject yuyue = CodeUtils.getUiObject_textOrClass("您的预约汇款交易受理成功，请查询收款账户的到账情况，并确认交易结果。", "android.view.View");
            if (info0.exists()) {
                type = CodeUtils.getUiObject_content(info0);
                sleep(ChatClient.overtime_1);
                break;
            } else if (info2.exists()) {
                type = CodeUtils.getUiObject_content(info2);
                sleep(ChatClient.overtime_1);
                break;
            } else if (info4.exists()) {
                type = CodeUtils.getUiObject_content(info4);
                sleep(ChatClient.overtime_1);
                break;
            } else if (info6.exists()) {
                type = CodeUtils.getUiObject_content(info6);
                sleep(ChatClient.overtime_1);
                break;
            } else if (info8.exists()) {
                type = CodeUtils.getUiObject_content(info8);
                sleep(ChatClient.overtime_1);
                break;
            } else if (info10.exists()) {
                type = CodeUtils.getUiObject_content(info10);
                sleep(ChatClient.overtime_1);
                break;
            } else if (yuyue.exists()) {//大额预约
                showMsg("=====找到预约受理成功1===");
                String info = yuyue.getText();
                if (info.equals("您的预约汇款交易受理成功，请查询收款账户的到账情况，并确认交易结果。")) {
                    type = "大额预约汇款,请确认";
                }
                sleep(ChatClient.overtime_1);
                break;
            }
        }
        showMsg("=====进入转账完成===" + type);
        //获取转账完成状态
        String balance = "";
        if (Constants.getStr(type) == 0 || Constants.getStr(type) == 6) {
            DecimalFormat formater = new DecimalFormat("#0.##");
            balance = formater.format(Double.parseDouble(sumMoney) - Double.parseDouble(list.get(0).getMoney()));
            showMsg("保存余额...");
            String sumMoneyFile = user.getUserName() + bank.BANK_FLAG + "_sumMoney.txt";
            FileHelper.saveMoneySDFile(false, balance, sumMoneyFile);
        }
        sleep(ChatClient.overtime_2);
        showMsg("money:" + balance);
        type = type.replaceAll("\r|\n|\\s", "");
        ChatClient.reportTransferOrder(bank.BANK_NAME, type, balance, Constants.getStr(type));
        sleep(ChatClient.overtime_5);
        while (true) {
            UiObject back = CodeUtils.getUiObject_textOrClass("返回", "android.widget.Button");
            if (back.exists()) {
                back.click();
                showMsg("=====转账完成返回===");
                break;
            }
        }
        repeatClick();
    }

    /**
     * 停止受理 预约处理
     */
    private void ifStopDeal() throws UiObjectNotFoundException {
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            boolean outTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_15, "《转账汇款》查询超时...", Constants.notReport);
            if (outTime) {
                break;
            }
            if (isOverMax(list.get(0).getMoney())) {
                showMsg("=====准备查找预约处理===");
                UiObject info = CodeUtils.getUiObject_textOrClass("当前人民银行大额支付系统处于关闭状态， " +
                        "若您确认提交，我行将做预约处理，您的汇款将在下一个交易日工作时间处理，请确保下一交易日账户资金充足以完成汇款交易。", "android.view.View");
                UiObject btn = mDevice.findObject(new UiSelector().text("确认").className("android.widget.Button"));
                showMsg("=====检测大额转账是否成功===");
                if (info.exists()) {
                    showMsg("=====大额点击确认===");
                    type = "当前人民银行大额支付系统处于关闭状态，若您确认提交，我行将做预约处理，您的汇款将在下一个交易日工作时间处理，请确保下一交易日账户资金充足以完成汇款交易。";
                    btn.click();
                    break;
                }
            }
        }
    }

    /**
     * 重新点击 境内汇款
     */
    private void repeatClick() throws UiObjectNotFoundException {
        //网络不好的情况下，8s之内没有完成页面跳转，会进入到快速转账
        sleep(ChatClient.overtime_6);
        showMsg("=====准备点击境内汇款===");
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            boolean isOutTime = CodeUtils.outTime(ChatClient.begintime, ChatClient.overtime_30, "重回转账页超时", Constants.notReport);
            if (isOutTime) {
                mDevice.click((int) (360 * ratio), (int) (290 * ratio));
                sleep(ChatClient.overtime_1);
                break;
            }
            UiObject mBT_title = CodeUtils.getUiObject_textOrClass("汇款明细", "android.widget.Button");
            if (mBT_title.exists()) {
                UiObject view = mDevice.findObject(new UiSelector().resourceId("abs_pos_1"));
                UiObject view1 = view.getChild(new UiSelector().className("android.view.View").index(0));
                UiObject view2 = view1.getChild(new UiSelector().className("android.view.View").index(1));
                if (view2.exists()) {
                    view2.click();
                    showMsg("=====转账完成进入转账页面===");
                    break;
                }
            }
        }
        sleep(ChatClient.overtime_1);
    }

    /**
     * 设置开户行信息
     */
    private void setBankInfo(List<String> bankInfo) throws UiObjectNotFoundException, InterruptedException {
        //检测开户行弹窗
        isDialogBankAddress(bankInfo);
    }

    /**
     * 是否弹出开户行弹窗
     */
    private void isDialogBankAddress(List<String> bankInfo) throws UiObjectNotFoundException, InterruptedException {
        showMsg("==========检测是否有开户行弹窗==========");
        while (true) {
            sleep(2000);
            long nowtime = System.currentTimeMillis();
            if ((nowtime - ChatClient.begintime) > 20 * 1000) {
                showMsg("==========查找搜索控件超时=============");
                break;
            }
            UiObject search = mDevice.findObject(new UiSelector().text("输入网点号或关键字查询").resourceId("searcher"));
            UiObject search1 = mDevice.findObject(new UiSelector().descriptionContains("输入网点号或关键字查询").resourceId("searcher"));
            showMsg("---------查找搜索控件--------");
            if (search.exists()) {
                showMsg("---------找到搜索控件1--------");
                search.click();
                sleep(2000);
                showMsg("---------设置开户行--------");
                search.setText(bankInfo.get(2));
                sleep(2000);
                clickSearch();
                break;
            } else if (search1.exists()) {
                showMsg("---------找到搜索控件2--------");
                search1.click();
                sleep(2000);
                showMsg("---------设置开户行--------");
                search1.setText(bankInfo.get(2));
                sleep(2000);
                clickSearch();
                break;
            }
        }
        sleep(2000);
        int position = 0;
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        while (true) {
            sleep(2000);
            long nowtime = System.currentTimeMillis();
            if ((nowtime - ChatClient.begintime) > 10 * 1000) {
                showMsg("==========检测listview超时=============");
                break;
            }
            UiObject listView = mDevice.findObject(new UiSelector().className("android.widget.ListView").index(0));
            UiObject text = mDevice.findObject(new UiSelector().text("没有找到与“" + bankInfo.get(2) + "”相匹配的网点信息").className("android" +
                    ".view.View").index(0));
            UiObject text1 = mDevice.findObject(new UiSelector().descriptionContains("没有找到与“" + bankInfo.get(2) + "”相匹配的网点信息")
                    .className("android.view.View").index(2));
            showMsg("---------检测listview--------");
            if (listView.exists()) {
                showMsg("---------检测到listview--------");
                UiObject view = listView.getChild(new UiSelector().className("android.view.View").index(position));
                if (view.exists()) {
                    showMsg("---------检测到Item--------" + position);
                    String content = view.getText();
                    if (isContain(content, bankInfo)) {
                        view.click();
                        sleep(2000);
                        showMsg("--准备点击确定--");
                        clickSure();
                        break;
                    } else {
                        position++;
                    }
                }
            } else if (text.exists()) {
                String s = text.getText();
                showMsg("---------检测到提示信息--------" + s);
                sendUnBankInfo("未搜索到开户网点");
                showMsg("===上报未搜索到开户网点====");
                jumpOut();
                return;
            } else if (text1.exists()) {
                String s = text1.getContentDescription();
                showMsg("---------检测到提示信息--------" + s);
                sendUnBankInfo("未搜索到开户网点");
                showMsg("===上报未搜索到开户网点====");
                jumpOut();
                return;
            }
        }
        nextStep();
    }

    /**
     * 开户行点击键盘上的搜索键
     */
    private void clickSearch() {
        showMsg("---------点击了键盘的搜索键--------");
        mDevice.click((int) (660 * ratio), 1920);//键盘的搜索图标搜索
    }

    /**
     * 发送未搜索到开户行信息
     */
    private void sendUnBankInfo(String info) {
        String mobileD = "'devices':'" + getSerialNumber() + "','prot':'" + Constants.PROT + "','phoneModel':'工商银行','info':'" +
                info + "'";
        String json = "'order':'" + list.get(0).getOrder() + "','balance':'" + sumMoney + "','state':1,'type':1";
        ChatClient.msg("<YZF>{'header':'" + ChatClient.M_SEND_TRADE_RESULT_P + "'," + json + "," + mobileD + "}</YZF>");
        mapDelete(list.get(0).getOrder());
        showMsg("=====删除订单完成===");
        getmap();
        sleep(3000);
    }

    /**
     * 确认开户行
     */
    private void clickSure() throws UiObjectNotFoundException {
        sleep(3000);
        while (true) {
            long nowtime = System.currentTimeMillis();
            if ((nowtime - ChatClient.begintime) > 15 * 1000) {
                showMsg("==========检测确定按钮超时=============");
                break;
            }
            UiObject vue = mDevice.findObject(new UiSelector().className("android.view.View").resourceId("my-vue-app"));
            UiObject view = vue.getChild(new UiSelector().className("android.view.View").index(2));
            UiObject view1 = view.getChild(new UiSelector().className("android.view.View").index(1));
            UiObject sure = view1.getChild(new UiSelector().text("确定").className("android.widget.Button").index(4));
            showMsg("---------检测确定按钮--------");
            if (sure.exists()) {
                sure.click();
                break;
            }
        }
        sleep(3000);
    }

    /**
     * 查到支行信息的返回
     */
    private void jumpOut() throws UiObjectNotFoundException {
        sleep(2000);
        while (true) {
            UiObject back = mDevice.findObject(new UiSelector().text("返回").resourceId("returnButton"));
            UiObject back1 = mDevice.findObject(new UiSelector().descriptionContains("返回").resourceId("returnButton"));
            showMsg("---------检测开户行搜索结果返回按钮--------");
            if (back.exists()) {
                back.click();
                break;
            } else if (back1.exists()) {
                back1.click();
                break;
            }
        }
        sleep(2000);
        while (true) {
            UiObject back = mDevice.findObject(new UiSelector().text("返回").resourceId("returnButton"));
            UiObject back1 = mDevice.findObject(new UiSelector().descriptionContains("返回").resourceId("returnButton"));
            showMsg("---------检测开户行搜索界面返回按钮--------");
            if (back.exists()) {
                back.click();
                break;
            } else if (back1.exists()) {
                back1.click();
                break;
            }
        }
        sleep(2000);
        int i = 0;
        while (true) {
            sleep(2000);
            UiObject text = mDevice.findObject(new UiSelector().text("境内汇款").resourceId("nav_title"));
            UiObject text1 = mDevice.findObject(new UiSelector().descriptionContains("境内汇款").resourceId("nav_title"));
            showMsg("---------检测境内汇款界面返回按钮--------");
            if (text.exists()) {
                while (true) {
                    UiObject back = mDevice.findObject(new UiSelector().text("返回").resourceId("returnButton"));
                    UiObject back1 = mDevice.findObject(new UiSelector().descriptionContains("返回").resourceId("returnButton"));
                    if (back.exists()) {
                        showMsg("---------点击境内汇款界面返回按钮--------" + i);
                        back.click();
                        break;
                    } else if (back1.exists()) {
                        showMsg("---------点击境内汇款界面返回按钮--------" + i);
                        back1.click();
                        break;
                    }
                }
                break;
            } else if (text1.exists()) {
                while (true) {
                    UiObject back = mDevice.findObject(new UiSelector().text("返回").resourceId("returnButton"));
                    UiObject back1 = mDevice.findObject(new UiSelector().descriptionContains("返回").resourceId("returnButton"));
                    if (back.exists()) {
                        showMsg("---------点击境内汇款界面返回按钮--------" + i);
                        back.click();
                        break;
                    } else if (back1.exists()) {
                        showMsg("---------点击境内汇款界面返回按钮--------" + i);
                        back1.click();
                        break;
                    }
                }
                break;
            }
        }
        sleep(2000);
        while (true) {
            sleep(2000);
            long nowtime = System.currentTimeMillis();
            if ((nowtime - ChatClient.begintime) > 30 * 1000) {
                showMsg("==========检测转账汇款按钮超时=============");
                break;
            }
            UiObject grid = mDevice.findObject(new UiSelector().className("android.widget.GridView").resourceId("com" +
                    ".icbc:id/main_menu"));
            UiObject layout = grid.getChild(new UiSelector().className("android.widget.LinearLayout").index(1));
            showMsg("---------检测转账汇款按钮--------");
            if (layout.exists()) {
                showMsg("---------点击转账汇款按钮--------");
                layout.click();
                break;
            }
        }
        sleep(2000);
        ChatClient.begintime = System.currentTimeMillis();//开始时间
        showMsg("=====准备点击境内汇款===");
        while (true) {
            long nowtime = System.currentTimeMillis();
            if ((nowtime - ChatClient.begintime) > ChatClient.overtime_30) {
                sleep(ChatClient.overtime_1);
                mDevice.click((int) (360 * ratio), (int) (290 * ratio));
                showMsg("=====转账完成进入转账页面超时===");
                break;
            }
            UiObject title0 = mDevice.findObject(new UiSelector().descriptionContains("汇款明细").className("android.widget.Button"));
            UiObject title1 = mDevice.findObject(new UiSelector().text("汇款明细").className("android.widget.Button"));
            if (title0.exists() || title1.exists()) {
                UiObject view = mDevice.findObject(new UiSelector().resourceId("abs_pos_1"));
                UiObject view1 = view.getChild(new UiSelector().className("android.view.View").index(0));
                UiObject view2 = view1.getChild(new UiSelector().className("android.view.View").index(1));
                if (view2.exists()) {
                    view2.click();
                    showMsg("=====转账完成进入转账页面===");
                    break;
                }
            }
        }
    }

    /**
     * 检测开户行是否正确
     */
    private boolean isContain(String content, List<String> bankInfo) {
        boolean b = false;
        if (bankInfo.get(1).contains(content)) {
            if (bankInfo.get(2).contains(content)) {
                b = true;
            }
        }
        return b;
    }

    /**
     * 判断是否达到选择开户行的临界值
     *
     * @path sumMoney
     */
    private boolean isOverMax(String s) {
        boolean b = false;
        double c = 50000.00;//临界值为50000.00
        showMsg("===判断金额是否超过填写开户行的临界值====");
        double money = Double.parseDouble(s);
        if (money > c) {
            b = true;
        }
        showMsg("===判断金额是否超过填写开户行的临界值====" + b);
        return b;
    }

    boolean isABC = true;

    //输入密码 //#*&@
    public void putPwd(String pwd) throws InterruptedException {
        pwd = pwd.replace("#", "1").replace("*", "2").replace("&", "3").replace("@", "4");
        Thread.sleep(ChatClient.overtime_5);
        UIUtils.numAbc(pwd, new UIUtils.NumAbcListener() {
            @Override
            public void num2abc(boolean isNum2abd, String pwd) throws InterruptedException {
                if (isNum2abd) {
                    if (isABC) {
                        //在字母键盘
                        mDevice.click(970, 1560);
                        isABC = false;
                    }
                    Thread.sleep(ChatClient.overtime_3);
                    pwd = pwd.replace("1", "#").replace("2", "*").replace("3", "&").replace("4", "@");
                    setCharacter(pwd);
                } else {
                    if (!isABC) {
                        isABC = true;
                        mDevice.click(970, 1560);
                    }
                    Thread.sleep(ChatClient.overtime_3);
                    setClickNum(pwd);
                }
            }
        });
    }

    //输入字符
    public void setCharacter(String str) throws InterruptedException {

        char[] chars = str.toCharArray();

        for (int i = 0; i < chars.length; i++) {
            //#*&@
            Thread.sleep(1000);
            switch (chars[i] + "") {
                case "#":
                    mDevice.click(490, 1675);
                    break;
                case "*":
                    mDevice.click(810, 1675);
                    break;
                case "&":
                    mDevice.click(915, 1790);
                    break;
                case "@":
                    mDevice.click(1020, 1790);
                    break;
            }
        }
    }

    //截取字符串
    public String getCode(String msg) {
        if (msg == null || msg.isEmpty()) {
            return null;
        }
        int indexOf = msg.indexOf("验证码");
        String substring = msg.substring(indexOf + 3, indexOf + 9);
        return substring;

    }


    //输入键盘字母

    public void setClickNum(String pad_) {
        char[] abc = "qwertyuiopasdfghjklzxcvbnm".toCharArray();//char数组
        char[] pwd = pad_.toCharArray();//char数组
        for (int j = 0; j < pwd.length; j++) {
            for (int i = 0; i < abc.length; i++) {
                if (abc[i] == pwd[j]) {
                    mDevice.click(xy_abc[i][0], xy_abc[i][1]);
                    sleep(1000);
                    break;
                }
            }
        }
    }

    public void showLog(String msg) {
        Log.i("工商银行", msg);
    }

    public void showMsg(String msg) {
        LogToFile.showLog("工商银行", msg);
    }
}
